#ifndef _TEST_APP
#define _TEST_APP


#include "ofxArgs.h"

#include "ofxOsc.h"

#include "ofMain.h"
#include "ofxXmlSettings.h"
#include "cues.h"


class gpsZone {
public:
	float lon, lat;
	float radius;
	ofSoundPlayer sound;
	
	int numCues;
	int curCue[40];
	vector<Cue*> cues;
	float curTime;
	
};

class testApp : public ofBaseApp{
	private:
		ofxArgs* args;
		string option1, option2;
		bool flag1;
public:
	Cue * generateCueFromXml(ofxXmlSettings * XML, int i);
	
		testApp(ofxArgs* args);

	void setup();
	void update();
	void draw(){};

 ~testApp(){
		cout<<"BYE!"<<endl;
	}

	void keyPressed  (int key){};
	void keyReleased(int key){};
	void mouseMoved(int x, int y ){};
	void mouseDragged(int x, int y, int button){};
	void mousePressed(int x, int y, int button){};
	void mouseReleased(int x, int y, int button){};
	void windowResized(int w, int h){};

	void slog(string s, bool end=true);
	void loadSound(string file);

	ofSoundPlayer  sound;
	bool soundLoaded;
	string soundFilePath;
	string soundFiles[5];
	string logString;

	ofxOscReceiver oscRecv;
	ofxOscReceiver oscRecvTimeline;
	ofxOscSender oscSender;
	ofxOscSender oscSenderTimeline;

	ofxOscReceiver oscControlRecv;
	ofxOscSender oscControlSender;
	
	ofSerial	serial;
	bool serialConnected;

	static const int SET_CHANNEL_SHORT_BYTE = 71;
	static const int SET_CHANNEL_GROUP_BYTE = 72;
	static const int SET_CHANNEL_BYTE = 73;
	static const int DUSK_UPDATE = 74;
	static const int ASK_RESPONSE = 255;
	static const int GET_ACC =  75;
	static const int MSG_TIME_OUT = 100; //timeout in msec after which a non-received message is sent again


	void setOutput(int output, int val);
	void setOutputShort(int val[]);
	void setOutputGroup(int outputIn, int outputOut, int val);
	void updateDusk();
	void writeSerial(int msg);
	void queueMessage(int msg);
	void parseQueue();

	int duskValues[64];
	int duskSendValues[64];


	vector<int> msgQueue;
	int duskOutputs[64];
	int recvAcc[3];
	int curAcc0[3];
	vector<int> acc0;
	int shortSum;
	int arduinoBufferSize;
	bool msgLock; //message lock, active until last message is confirmed
	int lstMsg; //last message sent
	int lstMsgType; //if last message wasn't a type identifier, type is specified here
	int msgTimer,msgTimer2; //time since last message was sent
	bool connectedToArduino;
	bool receivingAcc;

	bool inputTimeline;
	bool inputGenerator;
	bool intputRandomNoise;
	bool intputSmoothRandomNoise;
	bool intputNone;

	bool intputAccVolume;

	//AccVolume
	float accVolume;
	float resumePoint;

	float volume;
	float lastVolume;
	float level;

	int lastSend;
	int lastRecv;

	int numBytes;

	float masterVolume;
	float masterVibration;

	int lowPass;

	bool panOnAcc;
	float ac1;

	unsigned char bytesReturned[4];
	char bytesReturned2[5];

	int computerNumber;
	bool button;
	
	ofxXmlSettings XML;
	int numCues;
	int curCue[40];
	vector<Cue*> cues;
	float curTime;
	
	string soundFile;
	string folder;
	
	string version;
	
	float filteredADC[3];
	bool masterAccOn;
	
	bool debug;
	
	float startTime;
	
	ofxXmlSettings settings;
	
	vector<gpsZone> zones;

};

#endif
